import api from '@/services/merchant-manager/shop';

export type MerchantManagerShopList = MerchantManagerShopApi.ListResponse;
export type MerchantManagerShopUserInfo = MerchantManagerShopApi.UserInfoResponse;

export const login = async (params: MerchantManagerShopApi.LoginParams) => {
  const res = await api.login(params);
  return res.data;
};
export const getAllList = async () => {
  const res = await api.getAllList<MerchantManagerShopApi.AllListResponse[]>();
  return res.data;
};
export const getFilterList = async () => {
  const res = await api.getFilterList();
  return res.data;
};
export const getList = async (params: MerchantManagerShopApi.ListParams) => {
  const res = await api.getList<MerchantManagerShopList>(params);
  const tableData: Requestor.TableFormatedData<MerchantManagerShopList> = {
    data: res.listData,
    current: res.page + 1,
    pageSize: res.limit,
    total: res.count,
    success: res.success,
  };

  return tableData;
};
export const getUserInfo = async (params: MerchantManagerShopApi.UserInfoParams) => {
  const res = await api.getUserInfo<MerchantManagerShopUserInfo>(params);
  const data = { ...res.data, realname: res.data.username };
  return data;
};
export const updateStatus = async (params: MerchantManagerShopApi.StatusParams) => {
  const data = await api.updateStatus(params);
  return data;
};
export default {
  login,
  getAllList,
  getFilterList,
  getList,
  getUserInfo,
  updateStatus,
};
